package ar.com.quickmart.configuration;

import android.content.Context;
import android.content.SharedPreferences;
import ar.com.quickmart.R;

public class ConfigurationManager {

	private static ConfigurationManager configurationManager;
	private static Context context;
	private static SharedPreferences sharedPreferences;
	
	private ConfigurationManager() {
	}
	
	public static ConfigurationManager getInstance(Context context){ 
		
		// Si no esta instanciado
		if(configurationManager == null) {
			configurationManager = new ConfigurationManager();
		}
		ConfigurationManager.context = context;
		sharedPreferences = context.getSharedPreferences(ConfigurationManager.context.getResources().getString(R.string.preferencesFile),
														Context.MODE_PRIVATE);
		return configurationManager;
	}
	
	public void setUser(String username) {
		
		// Variables
		SharedPreferences.Editor editor = sharedPreferences.edit();
		
		// Guardo el username
		editor.putString("username", username);
		
		// Indico que esta logueado
		editor.putBoolean("logged", true);
		
		editor.commit();
	}
	
	public boolean isUserLogged() {		
		return sharedPreferences.getBoolean("logged", false);
	}
	
	public String getUserName() {
		return sharedPreferences.getString("username", null);
	}
	
	public void logout() {
		// Variables
		SharedPreferences.Editor editor = sharedPreferences.edit();
		
		// Indico que esta logueado
		editor.putBoolean("logged", false);
		
		editor.commit();
	}

	
}
